<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
</head>

<body>
  <div>
    <button id="button">同源请求</button>
    <button id="crossButton">跨域请求</button>
  </div>
  <script>
    const button = document.querySelector("#button");
    const crossButton = document.querySelector("#crossButton");

    axios.get("http://localhost:3001/login", {

    }).then((res) => {
      console.log(res);
    });
    // 发送同域请求
    button.onclick = function () {
      axios.get("http://localhost:3001/getUser", {}).then((res) => {
        console.log(res);
      });
    };
    // 发送跨域请求
    crossButton.onclick = function () {
      axios({
        withCredentials: true, // ++
        method: "get",
        url: "http://localhost:3002/crossList",
      }).then((res) => {
        console.log(res);
      });
    };

  </script>

</body>

</html>